#!/usr/bin/perl
#edit_share.cgi

require './shareman-lib.pl';



&ReadParse();

&error_setup($text{'edit_share_error'});

my $emode = $in{'edit'};
my $source = $in{'src'};
my $spath = $in{'sharepath'};
my $alertmsg;

if ( $emode eq 'create')
{
	my $mntroot = &get_mnt_root();
	my @mntvols = &get_volumes();
	if (($mntroot eq "")||(@mntvols == 0))
	{
		&error($text{'invalid_volumes'});
	}
}

if ( $emode eq 'property')
{
	my $folder;
	
	$folder = $in{'sharepath'};
	$folder =~ s/^.*\///g;
	if ($folder =~ /[^A-Za-z0-9\x7f-\xff\.\+\_\-\(\)]/)
	{
		my ($err_msg, $log_ev, $log_msg);

		$err_msg = &text('err_msg_editshare_patherrformat', $folder);
		$log_msg = &text('log_msg_save_locgroup_notexist', $folder);
		$log_ev = $text{'log_ev_editshare_patherrformat'};
		&nas_syslog("shareman", "naslog_warning", $log_ev, $log_msg);
		&error($err_msg);
	}
}

if (($emode eq 'create')||($emode eq 'property'))
{
	if ($source eq 'disk')
	{
		$in{'cat'} = "W";

		#for cifs
#		$in{'availablerdn'} = "yes";
#		$in{'browserdn'} = "yes";
#		$in{'writablerdn'} = "no";
#		$in{'guestrdn'} = "0";
#		$in{'guestin'} = "nobody";
#		$in{'limitlistrdn'} = "no";
#		$in{'hostallowrdn'} = "0";
#		$in{'onlyallow'} = "";
#		$in{'hostdenyrdn'} = "0";
#		$in{'onlydeny'} = "";
#		$in{'revalidrdn'} = "no";
#		$in{'validusersin'} = "";
#		$in{'validgroupsin'} = "";
#		$in{'invalidusersin'} = "";
#		$in{'invalidgroupsin'} = "";
#		$in{'possibleusersin'} = "";
#		$in{'possiblegroupsin'} = "";
#		$in{'readonlyusersin'} = "";
#		$in{'readonlygroupsin'} = "";
#		$in{'readwriteusersin'} = "";
#		$in{'readwritegroupsin'} = "";
#		$in{'forceuserin'} = "";
#		$in{'forcegroupin'} = "";
		$in{'maxconnect'} = "0";
		$in{'maxconnectionin'} = "";

		$in{'usertyperdn'} = "0";
		$in{'trustusercache'} = "";
		$in{'othersel'} = "2";

		#for nfs
		#$in{'exporthost'} = "0";
		#$in{'hostin'} = "";
		#$in{'netgroupin'} = "";
		#$in{'netmaskin'} = "";
		#$in{'hostlistcache'} = "$text{'everyone'} $text{'readwrite'}:0,,n,1,n,1:-1";
		#$in{'linkradio'} = "n";
		#$in{'accessmd'} = "1";
		#$in{'denymd'} = "n";
		#$in{'trustmd'} = "1";

		$in{'trusthostcache'} = "0,,0,0";


		#for ftp
		$in{'allowanony'} = "";
		$in{'allowgroup'} = "y";
		$in{'ftpgroupin'} = "";
		$in{'allowreadbox'} = "r";
		$in{'allowwritebox'} = "";

		#for http
		$in{'needauthrdn'} = "n";
		#$in{'realmrdn'} = "0";
		#$in{'realmin'} = "";
		$in{'accessloginrdn'} = "0";
		$in{'onlyusersin'} = "";
		$in{'onlygroupsin'} = "";
		#$in{'satisfyrdn'} = "0";
		#$in{'checkorderrdn'} = "1";
		#$in{'actionadd'} = "0";
		#$in{'conditionadd'} = "0";
		#$in{'conditionaddin'} = "";
		#$in{'restrictlistcache'} = "0,0,";

		if ($emode eq 'create')
		{
			$in{'sharepath'} = "";
			$in{'sharename'} = "";
			$in{'oldsharename'} = "";
			$in{'sharetype'} = "W";
			$in{'comment'} = "";

		}
		else
		{
			my @si = search_shareinfo($in{'sharepath'});
			$in{'sharename'} = $si[0];
			$in{'oldsharename'} = $si[0];
			$in{'sharetype'} = $si[1];
			$in{'comment'} = $si[2];

			if ($in{'sharetype'} =~ /W/)
			{
				if (&check_cifs_config($si[0]))
				{
					&foreign_require("samba", "samba-lib.pl");
					%econfig = &foreign_config("samba");
					&lock_file($econfig{'smb_conf'});
					&foreign_call("samba", "get_share", $si[0]);
					if (&foreign_call("samba", "getval", "path") eq $in{'sharepath'})
					{
						local @valid_users, @invalid_users, @read_list, @write_list;
						$available = &foreign_call("samba", "getval", "available");
						#$in{'browserdn'} = &foreign_call("samba", "getval", "browseable");
						$writable = &foreign_call("samba", "getval", "writable");
						#my $a1 = &foreign_call("samba", "getval", "public");
						#my $b1 = &foreign_call("samba", "getval", "guest only");
						#if (($a1 eq "no") && ($b1 eq "no"))
						#{
						#	$in{'guestrdn'} = "0";
						#}
						#elsif (($a1 eq "yes") && ($b1 eq "no"))
						#{
						#	$in{'guestrdn'} = "1";
						#}
						#elsif (($a1 eq "yes") && ($b1 eq "yes"))
						#{
						#	$in{'guestrdn'} = "2";
						#}
						#$in{'guestin'} = &foreign_call("samba", "getval", "guest account");
						#$in{'limitlistrdn'} = &foreign_call("samba", "getval", "only user");
						#my $c1 = &foreign_call("samba", "getval", "allow hosts");
						#$in{'hostallowrdn'} = (!$c1)?"0":"1";
						#$in{'onlyallow'} = $c1;
						#my $d1 = &foreign_call("samba", "getval", "deny hosts");
						#$in{'hostdenyrdn'} = (!$d1)?"0":"1";
						#$in{'onlydeny'} = $d1;
						#$in{'revalidrdn'} = &foreign_call("samba", "getval", "revalidate");
						$in{'trustusercache'} = "";
						if ($available eq "yes")
						{
							$tstr = &foreign_call("samba", "getval", "valid users");
							$tstr =~ s/\"//g;
							@valid_users = &split_users($tstr);
							$tstr = &foreign_call("samba", "getval", "invalid users");
							$tstr =~ s/\"//g;
							@invalid_users = &split_users($tstr);
							$tstr = &foreign_call("samba", "getval", "read list");
							$tstr =~ s/\"//g;
							@read_list = &split_users($tstr);
							$tstr = &foreign_call("samba", "getval", "write list");
							$tstr =~ s/\"//g;
							@write_list = &split_users($tstr);
						}	
						#$in{'validusersin'} = join(' ', grep { !/^@/ } @valid_users);
						#$in{'validgroupsin'} = join(' ', map { s/@//;$_ } grep { /^@/ } @valid_users);
						if ((@valid_users > 0)||($available eq "no"))
						{
							$in{'othersel'} = "2";
						}
						elsif ($writable eq "yes")
						{
							$in{'othersel'} = "1";
						}
						else
						{
							$in{'othersel'} = "0";
						}

						if (@valid_users > 0)
						{
							foreach $d (@valid_users) {
								@invalids = grep { $d eq $_ } @invalid_users;
								if (@invalid == 0)
								{
									@reads = grep { $d eq $_ } @read_list;
									@writes = grep { $d eq $_ } @write_list;
									if ((@reads ==0) && (@writes == 0))
									{
										if ($writable eq "yes")
										{
											push(@write_list, $d);
										}
										else
										{
											push(@read_list, $d);
										}
									}
								}
							}
						}


						#$in{'invalidusersin'} = join(' ', grep { !/^@/ } @invalid_users);
						#$in{'invalidgroupsin'} = join(' ', map { s/@//;$_ } grep { /^@/ } @invalid_users);
						#@user = &split_users(&foreign_call("samba", "getval", "user"));
						#$in{'possibleusersin'} = join(' ', grep { !/^@/ } @user);
						#$in{'possiblegroupsin'} = join(' ', map { s/@//;$_ } grep { /^@/ } @user);


						#$in{'readonlyusersin'} = join(' ', grep { !/^@/ } @read_list);
						#$in{'readonlygroupsin'} = join(' ', map { s/@//;$_ } grep { /^@/ } @read_list);
						#@readuserlist = grep { !/^@/ } @readlist;
						#@readgrouplist = map { s/@//;$_ } grep { /^@/ } @read_list;
						foreach $d (@read_list) {
							@invalids = grep { $d eq $_ } @invalid_users;
							if (@invalids > 0)
							{
								next;
							}
							if (@valid_users > 0)
							{
								@valids = grep { $d eq $_ } @valid_users;
								if (@valids == 0)
								{
									push(@invalid_users, $d);
									next;
								}
							}
							if ($d =~ /^@/)
							{
								$d =~ s/@//;
								if ($d =~ /\\/)
								{
									$in{'trustusercache'} .="3";
								}
								else
								{
									$in{'trustusercache'} .="1";
								}
								$in{'trustusercache'} .= ",$d,0:";
							}
							else
							{
								if ($d =~ /\\/)
								{
									$in{'trustusercache'} .="2";
								}
								else
								{
									$in{'trustusercache'} .="0";
								}
								$in{'trustusercache'} .= ",$d,0:";
							}
						}

						#$in{'readwriteusersin'} = join(' ', grep { !/^@/ } @write_list);
						#$in{'readwritegroupsin'} = join(' ', map { s/@//;$_ } grep { /^@/ } @write_list);
						foreach $d (@write_list) {
							@invalids = grep { $d eq $_ } @invalid_users;
							if (@invalids > 0)
							{
								next;
							}
							if (@valid_users > 0)
							{
								@valids = grep { $d eq $_ } @valid_users;
								if (@valids == 0)
								{
									push(@invalid_users, $d);
									next;
								}
							}
							if ($d =~ /^@/)
							{
								$d =~ s/@//;
								if ($d =~ /\\/)
								{
									$in{'trustusercache'} .="3";
								}
								else
								{
									$in{'trustusercache'} .="1";
								}
								$in{'trustusercache'} .= ",$d,1:";
							}
							else
							{
								if ($d =~ /\\/)
								{
									$in{'trustusercache'} .="2";
								}
								else
								{
									$in{'trustusercache'} .="0";
								}
								$in{'trustusercache'} .= ",$d,1:";
							}
						}

						foreach $d (@invalid_users) {
							if ($d =~ /^@/)
							{
								$d =~ s/@//;
								if ($d =~ /\\/)
								{
									$in{'trustusercache'} .="3";
								}
								else
								{
									$in{'trustusercache'} .="1";
								}
								$in{'trustusercache'} .= ",$d,2:";
							}
							else
							{
								if ($d =~ /\\/)
								{
									$in{'trustusercache'} .="2";
								}
								else
								{
									$in{'trustusercache'} .="0";
								}
								$in{'trustusercache'} .= ",$d,2:";
							}
						}
						#$in{'forceuserin'} = &foreign_call("samba", "getval", "force user");
						#$in{'forcegroupin'} = &foreign_call("samba", "getval", "force group");
						my $e1 = &foreign_call("samba", "getval", "max connections");
						$in{'maxconnect'} = (($e1 == 0)?"0":"1");
						$in{'maxconnectionin'} = ($e1 > 0)?$e1:"";
					}

					&unlock_file($econfig{'smb_conf'});
				}
			}

			if ($in{'sharetype'} =~ /U/)
			{
				my @nfsparam = &check_nfs_config($in{'sharepath'});
				if ($nfsparam[0])
				{
					#$in{'hostlistcache'} = "";
					splice(@nfsparam, 0, 1);
					&foreign_require("exports", "exports-lib.pl");
					%econfig = &foreign_config("exports");
					&lock_file($econfig{'exports_file'});
					$in{'hostlistcache'} = &load_export_by_indexes(\@nfsparam);
					$in{'trusthostcache'} = &load_exports_by_indexes(\@nfsparam);
					&unlock_file($econfig{'exports_file'});
					$in{'hostlistcache'} .= "-1";

				}
				else
				{
					$in{'hostlistcache'} ="";
					$in{'trusthostcache'} = "";
				}
			}

			if ($in{'sharetype'} =~ /F/)
			{				
				unless($in{'trustftpusercache'})
				{
					&foreign_require("pureftpd", "pureftpd-lib.pl");
					$in{'trustftpusercache'} = &foreign_call("pureftpd", "get_ftp_dir", $in{'sharepath'});;
				}
			}

			if ($in{'sharetype'} =~ /H/)
			{
				my @httpparam = &check_http_config($in{'sharename'},$in{'sharepath'});
				if ($httpparam[0])
				{
					$in{'checkorderrdn'} = "3";
					$in{'restrictlistcache'} = "";
					&foreign_require("apache", "apache-lib.pl");
					my $d = $httpparam[3];
					my $conf = $d->{'members'};
					foreach $subd (@$conf) {
						if (($subd->{'name'} eq "AllowOverride")&&($subd->{'value'} =~ /AuthConfig/))
						{
							$in{'needauthrdn'} = 'y';
						}
						#if ($subd->{'name'} eq "AuthName")
						#{
						#	$in{'realmrdn'} = '1';
						#	($subd->{'value'}) =~ /^\"(.*)\"$/;
						#	$in{'realmin'} = $1;
						#}
						if ($subd->{'name'} eq "require")
						{
							if ($subd->{'words'}->[0] eq "user")
							{
								$in{'accessloginrdn'} = "1";
								$tempstr = $subd->{'value'};
								$tempstr =~ s/user //;
								$in{'onlyusersin'} = $tempstr;
							}
							elsif ($subd->{'words'}->[0] eq "group")
							{
								$in{'accessloginrdn'} = "2";
								$tempstr = $subd->{'value'};
								$tempstr =~ s/group //;
								$in{'onlygroupsin'} = $tempstr;
							}
							if ($subd->{'words'}->[0] eq "valid-user")
							{
								$in{'accessloginrdn'} = "0";
							}
						}
					}
				}
			}
			if ($in{'sharetype'} =~ /A/)
			{
				my $str, %afp_volcfg;
				$str = &afp_get($in{'sharename'}, $in{'sharepath'}, \%afp_volcfg);
				
				unless($in{'afptrustusercache'})
				{
					$in{'afptrustusercache'} = $str;
				}
				unless($in{'afp_mountRO'})
				{
					$in{'afp_mountRO'} = 'yes' if ($afp_volcfg{'options'} =~ /ro/);
				}
				unless($in{'afp_passwd'})
				{
					$in{'afp_passwd'} = $afp_volcfg{'password'} if ($afp_volcfg{'password'});
				}
				unless($in{'afp_allowguest'})
				{
					$in{'afp_allowguest'} = 'yes' if ($afp_volcfg{'allowguest'});
				}
			}
		}
	}

	if ($in{'cat'} eq "")
	{
		$in{'cat'} = "0";	#just not empty and different from other sharetypes
	}	
	if (!($in{'sharetype'} =~ /$in{'cat'}/))
	{
		$in{'sharetype'} =~ /(W|U|F|H|A)/;
		$in{'cat'} = $1;
	}
	if ($emode eq 'create')
	{
		&header($text{'create_share_title'}, "", "createshare", 0, 1);
	}
	else
	{
		&header($text{'edit_share_title'}, "", "editshare", 0, 1);
	}
#	print "<hr>\n";
	#print "<h3>Select Option() constructor</h3>";
	print "<form action=edit_share.cgi method=post onsubmit='document.forms[0].saveshare.disabled = true;'>\n";
	print "<input type=hidden name=edit value='$emode'>\n";
	print "<input type=hidden name=src value='cache'>\n";
	print "<input type=hidden name=cat value='$in{'cat'}'>\n";
	print "<input type=hidden name=oldsharename value='$in{'oldsharename'}'>\n";
	print "<table class=group border=1 cellpadding=4 cellspacing=0 width=100%>\n";
	print "<tr class=title1> <td class=group><b>$text{'general_title'}</b></td> </tr>\n";
	print "<tr> <td class=group><table class=mode1 cellpadding=3 cellspacing=0 width=100%>\n";
	print "<tr> <td><b>$text{'sharename'}</b></td>\n";
	print "<td><input name=sharename value='$in{'sharename'}' class=text></td>\n";
	print "<td><b>$text{'sharepath'}</b></td>\n";
	if ($emode eq 'create')
	{
		@vols = get_volumes();
		print "<td>\n";
		print "<select name=selvol>\n";
		foreach $v (@vols)
		{
			printf "<option %s value='$v'>$v\n", ($in{'selvol'} eq $v)?"selected":"";
		}
		print "</select>\n";
#		printf "<input name=sharepath value='$in{'sharepath'}' class=text> %s\n", ezstor_file_chooser_button("sharepath", 1);
		print "<input name=sharepath value='$in{'sharepath'}' class=text>\n";
		printf "<input type=checkbox name=createfolder %s value='y'>$text{'createfolder_notexist'}</td> </tr>\n", (($source eq 'cache')&&($in{'createfolder'} eq 'y'))?"checked":"";
	}
	else
	{
		print "<td><input type=hidden name=sharepath value='$in{'sharepath'}'>\n";
		print "<b>$in{'sharepath'}</b></td> </tr>\n";

	}
	print "<tr> <td><b>$text{'comment'}</b></td>\n";
	print "<td><input name=comment value='$in{'comment'}' class=text></td>\n";
	print "<td><b>$text{'sharetype'}</b></td>\n";
	printf "<td><input type=checkbox name=sharetype value='W' %s onclick='RefreshPage()'>$text{'cifs'}\n", ($in{'sharetype'} =~ /W/)?"checked":"";
	printf "<input type=checkbox name=sharetype value='U' %s onclick='RefreshPage()'>$text{'nfs'}\n", ($in{'sharetype'} =~ /U/)?"checked":"";
	printf "<input type=checkbox name=sharetype value='F' %s onclick='RefreshPage()'>$text{'ftp'}\n", ($in{'sharetype'} =~ /F/)?"checked":"";
	printf "<input type=checkbox name=sharetype value='H' %s onclick='RefreshPage()'>$text{'http'}\n", ($in{'sharetype'} =~ /H/)?"checked":"";
	#printf "<input type=checkbox name=sharetype value='A' %s onclick='RefreshPage()'>$text{'afp'}\n", ($in{'sharetype'} =~ /A/)?"checked":"";
	print "</td></tr>";
	print "</table></td></tr></table><p>\n";

	#generate tab pages,including cifs nfs ftp http
	print "<table class=group border=0 cellpadding=0 cellspacing=0 height=20 width=100%><tr>\n";
	if($in{'sharetype'} =~ /W/)
	{
		#print "<td valign=top $cb>", "<br>", "</td>\n";
		if ($in{'cat'} =~ /W/)
		{
			print "<td class=front nowrap>&nbsp;<b>$text{'cifs_share_title'}</b>&nbsp;</td>\n";
		}
		else
		{
			print "<td class=behind nowrap>&nbsp;",
		      		"<a href=\"\" onclick='change_category(\"W\");return false'><b>$text{'cifs_share_title'}</b></a>&nbsp;</td>\n";
		}
		#print "<td valign=top $cb>", "<br>", "</td>\n";
		print "<td class=blank>&nbsp;&nbsp;</td>\n";
	}
	if($in{'sharetype'} =~ /U/)
	{
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		if ($in{'cat'} =~ /U/)
		{
			print "<td class=front nowrap>&nbsp;<b>$text{'nfs_share_title'}</b>&nbsp;</td>\n";
		}
		else
		{
			print "<td class=behind nowrap>&nbsp;",
		      		"<a href=\"\" onclick='change_category(\"U\");return false'><b>$text{'nfs_share_title'}</b></a>&nbsp;</td>\n";
		}
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		print "<td class=blank>&nbsp;&nbsp;</td>\n";
	}
	if($in{'sharetype'} =~ /F/)
	{
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		if ($in{'cat'} =~ /F/)
		{
			print "<td class=front nowrap>&nbsp;<b>$text{'ftp_share_title'}</b>&nbsp;</td>\n";
		}
		else
		{
			print "<td class=behind nowrap>&nbsp;",
		      		"<a href=\"\" onclick='change_category(\"F\");return false'><b>$text{'ftp_share_title'}</b></a>&nbsp;</td>\n";
		}
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		print "<td class=blank>&nbsp;&nbsp;</td>\n";
	}
	if($in{'sharetype'} =~ /H/)
	{
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		if ($in{'cat'} =~ /H/)
		{
			print "<td class=front nowrap>&nbsp;<b>$text{'http_share_title'}</b>&nbsp;</td>\n";
		}
		else
		{
			print "<td class=behind nowrap>&nbsp;",
			      "<a href=\"\" onclick='change_category(\"H\");return false'><b>$text{'http_share_title'}</b></a>&nbsp;</td>\n";
		}
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		print "<td class=blank>&nbsp;&nbsp;</td>\n";
	}

	if($in{'sharetype'} =~ /A/)
	{
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		if ($in{'cat'} =~ /A/)
		{
			print "<td class=front nowrap>&nbsp;<b>$text{'afp_share_title'}</b>&nbsp;</td>\n";
		}
		else
		{
			print "<td class=behind nowrap>&nbsp;",
			      "<a href=\"\" onclick='change_category(\"A\");return false'><b>$text{'afp_share_title'}</b></a>&nbsp;</td>\n";
		}
		#print "<td valign=top $tb>", "<br>", "</td>\n";
		print "<td class=blank>&nbsp;&nbsp;</td>\n";
	}

	print "<td class=blank width=100%>&nbsp;</td>\n" if ($in{'sharetype'} =~ /W|U|F|H|A/);
	print "</tr></table>\n";

	#generate cifs page
	if($in{'cat'} =~ /W/)
	{
	#print "<hr>\n";
		my (@file, @line);
		my @c_usertype = ($text{'local_user'}, $text{'local_group'}, $text{'pdc_user'}, $text{'pdc_group'});

		print "<table class=tabpage cellpadding=5 cellspacing=0 width=100%>\n";
		print "<tr> <td valign=top><div class=small><table class=mode1 border=0 cellspacing=0 cellpadding=1 width=100%>\n";
		print "<tr> <td colspan=3><b>$text{'trustedusers'}</b></td></tr>\n";
		print "<tr class=title1> <th align=left>$text{'name'}</th> ",
			"<th align=left>$text{'accessmode'}</th> ",
			"<th align=left>$text{'usertype'}</th> </tr>\n";
		@trustusers = split(":", $in{'trustusercache'});
		&sort_cifs_uglist(\@trustusers, "name");
		$n = @trustusers;
		for ($i = 0; $i < @trustusers; $i ++)
		{
			if ($i % 2 eq 1)
			{
				$dismode = "class=mode2";
			}
			else
			{
				$dismode = "class=mode1";
			}
			my @thlist = split(',', $trustusers[$i]);
			print "<tr $dismode> <td><input type=radio name=cifstrustrdn><input type=hidden name=cifsuseritem value='$thlist[0],$thlist[1]'>$thlist[1]</td>\n";


			print "<td><select name=cifsaccessitem class=drop onchange='cachecifslist($n)'>\n";
			printf "<option %s value='0'>$text{'readonly'}\n", ($thlist[2] eq "0")?"selected":"";
			printf "<option %s value='1'>$text{'readwrite'}\n", ($thlist[2] eq "1")?"selected":"";
			printf "<option %s value='2'>$text{'denyaccess'}\n", ($thlist[2] eq "2")?"selected":"";
			print "</select></td>\n";
			print "<td>$c_usertype[$thlist[0]]</td> </tr>\n";



		}

		if ($n % 2 eq 1)
			{
				$dismode = "class=mode2";
			}
			else
			{
				$dismode = "class=mode1";
			}
		print "<tr $dismode><td><b>$text{'other_users'}</b></td>\n";
		print "<td colspan=2><select name=othersel class=drop>\n";
		printf "<option %s value='0'>$text{'readonly'}\n", ($in{'othersel'} eq "0")?"selected":"";
		printf "<option %s value='1'>$text{'readwrite'}\n", ($in{'othersel'} eq "1")?"selected":"";
		printf "<option %s value='2'>$text{'denyaccess'}\n", ($in{'othersel'} eq "2")?"selected":"";
		print "</select></td> </tr>\n";

		print "</table></div></td>\n";
		$in{'trustusercache'} = join(":", @trustusers);
		print "<input type=hidden name=trustusercache value=\"$in{'trustusercache'}\">\n";


		print "<td><table class=mode1 border=0 cellspacing=8 cellpadding=1 width=100%>\n";
		print "<tr> <td align=center><b>$text{'accessmode'}</b>\n";
		print "<select name=cifsaccesssel>\n";
		print "<option value='0'>$text{'readonly'}\n";
		print "<option value='1'>$text{'readwrite'}\n";
		print "<option value='2'>$text{'denyaccess'}\n";
		print "</select></td> </tr>\n";
		print "<tr><td align=center><input type=button name=addcifsuserbtn value=\"$text{'add'}\" onclick='addcifstrustlist($n);' class=button1></td> </tr>\n";
		print "<tr> <td align=center><input type=button name=removecifsuserbtn value=\"$text{'remove'}\" onclick='removecifstrustlist($n);' class=button1></td></tr>\n";
		print "</table></td>\n";
		print "<td valign=top width=200><table class=mode1 border=0 cellspacing=0 cellpadding=1 width=100%>\n";
		print "<tr> <td><b>$text{'allusers'}</b></td> </tr>\n";
		print "<tr> <td><select name=usertyperdn onchange='change_user_list();'>\n";
		printf "<option %s value='0'>$text{'show_localuser'}\n", ($in{'usertyperdn'} eq "0")?"selected":"";
		printf "<option %s value='1'>$text{'show_localgroup'}\n", ($in{'usertyperdn'} eq "1")?"selected":"";
		printf "<option %s value='2'>$text{'show_pdcuser'}\n", ($in{'usertyperdn'} eq "2")?"selected":"";
		printf "<option %s value='3'>$text{'show_pdcgroup'}\n", ($in{'usertyperdn'} eq "3")?"selected":"";
		printf "</select></td></tr>\n";
		#print "<tr class=title1> <th align=left>$text{'usertype'}</th> ",
		#	"<th align=left>$text{'name'}</th> </tr>\n";
		#$n = 0;

		unless($in{'usertyperdn'})
		{
			$in{'usertyperdn'} = 0;
		}

		print "<tr> <td><select name=userslist size=10 class=list>\n";
		if ($in{'usertyperdn'} eq "0")
		{
			open(LOCALUSER, $config{'localuser_file'});
			@file = <LOCALUSER>;
			close(LOCALUSER);

			for($i = @file - 1; $i >= 0; $i--)
			{
				chomp($file[$i]);
				$file[$i] =~ s/#.*$//;
				@line = split(':', $file[$i]);
				if($line[0])
				{
					$file[$i] = $line[0];
				}
				else
				{
					splice @file, $i, 1;
				}
			}

			@file = sort {$a cmp $b} @file;

			for($i = 0; $i < @file; $i++)
			{
				print "<option value=\'$file[$i]\'>$file[$i]\n";
			}
		}

		if ($in{'usertyperdn'} eq "1")
		{
			open(LOCALGROUP, $config{'localgroup_file'});

			@file = <LOCALGROUP>;
			close(LOCALGROUP);

			for($i = @file - 1; $i >= 0; $i--)
			{
				chomp($file[$i]);
				$file[$i] =~ s/#.*$//;

				splice(@file, $i, 1) unless($file[$i]);
			}

			@file = sort {$a cmp $b} @file;

			for($i = 0; $i < @file; $i++)
			{
				print "<option value=\'$file[$i]\'>$file[$i]\n";
			}
		}

		if ($in{'usertyperdn'} eq "2")
		{
			open(PDCUSER, $config{'pdcuser_file'});
			while ($line = <PDCUSER>) {
				$line =~ s/\r|\n//g;

			#print "<tr $dismode> <td><input type=radio name=alluserrdn value='2'>$text{'pdc_user'}</td>\n";
			#print "<td>$line</td> </tr>\n";
				print "<option value='$line'>$line\n";
			#$n ++;
			}
			close(PDCUSER);
		}

		if ($in{'usertyperdn'} eq "3")
		{
			open(PDCGROUP, $config{'pdcgroup_file'});
			while ($line = <PDCGROUP>) {
				$line =~ s/\r|\n//g;

				print "<option value='$line'>$line\n";
			}
			close(PDCGROUP);
		}
		print "</select></td> </tr>\n";

		print "</table></td> </tr>\n";

		print "<tr> <td colspan=3><b>$text{'max_connections'}</b>\n";
		printf "<input type=radio name=maxconnect %s value='0' onclick='changeconnection();'>$text{'unlimit'}\n", ($in{'maxconnect'} =~ /0/)?"checked":"";
		printf "<input type=radio name=maxconnect %s value='1' onclick='changeconnection();'><input name=maxconnectionin %s class=%s size=5 value='$in{'maxconnectionin'}'></td> </tr>\n", ($in{'maxconnect'} =~ /1/)?"checked":"", ($in{'maxconnect'} =~ /1/)?"":"disabled=true", ($in{'maxconnect'} =~ /1/)?"text":"disabletext";


		print "</table><p>\n";
	}
	else
	{
		print "<input type=hidden name=maxconnect value='$in{'maxconnect'}'>\n";
		print "<input type=hidden name=maxconnectionin value='$in{'maxconnectionin'}'>\n";

		print "<input type=hidden name=usertyperdn value='$in{'usertyperdn'}'>\n";
		print "<input type=hidden name=trustusercache value=\"$in{'trustusercache'}\">\n";
		print "<input type=hidden name=othersel value='$in{'othersel'}'>\n";
	}

	#generate nfs page
	if($in{'cat'} =~ /U/)
	{
	#	print "<hr>\n";
		my @c_hosttype = ($text{'everyone'}, $text{'hosts'}, $text{'webnfs'}, $text{'netgroup'}, $text{'net_mask'});
		my @c_accessmd = ($text{'readonly'}, $text{'readwrite'}, $text{'denyaccess'});
		my @c_trustuser = ($text{'everyone'}, $text{'exceptroot'}, $text{'nobody'});
		print "<input type=hidden name=trusthostcache value=\"$in{'trusthostcache'}\">\n";
		print "<table class=tabpage cellpadding=5 cellspacing=0 width=100%>\n";
		#print "<tr $tb> <td><b>$text{'nfs_share_title'}</b></td> </tr>\n";
		#print "<tr> <td class=tabpage><hr></td> </tr>\n";
		print "<tr> <td valign=top width=70%><div class=small><table class=mode1 border=0 bordercolor=#33ccff cellspacing=0 cellpadding=1 width=100%>\n";
		print "<tr> <td colspan=3><b>$text{'trustedhosts'}</b></td></tr>\n";
		print "<tr class=title1> <th align=left>$text{'trusthost'}</th> ",
			"<th align=left>$text{'accessmode'}</th> ",
			"<th align=left>$text{'trustuser'}</th> </tr>\n";
		my @nfslist = split(':', $in{'trusthostcache'});
		$n = @nfslist;
		for ($i = 0; $i < @nfslist; $i ++)
		{
			if ($i % 2 eq 1)
			{
				$dismode = "class=mode2";
			}
			else
			{
				$dismode = "class=mode1";
			}
			my @thlist = split(',', $nfslist[$i]);
			print "<tr $dismode> <td><input type=radio name=nfshostrdn><input type=hidden name=hostitem value='$thlist[0],$thlist[1]'>$c_hosttype[$thlist[0]] $thlist[1]</td>\n";
			#print "<td>$c_accessmd[$thlist[2]]</td>\n";
			#print "<td>$c_trustuser[$thlist[3]]</td> </tr>\n";

			print "<td><select name=accessmodeitem class=drop onchange='cachenfslist($n)'>\n";
			printf "<option %s value='0'>$text{'readonly'}\n", ($thlist[2] eq "0")?"selected":"";
			printf "<option %s value='1'>$text{'readwrite'}\n", ($thlist[2] eq "1")?"selected":"";
			printf "<option %s value='2'>$text{'denyaccess'}\n", ($thlist[2] eq "2")?"selected":"";
			print "</select></td>\n";

			print "<td><select name=trustuseritem class=drop onchange='cachenfslist($n)'>\n";
			printf "<option %s value='0'>$text{'everyone'}\n", ($thlist[3] eq "0")?"selected":"";
			printf "<option %s value='1'>$text{'exceptroot'}\n", ($thlist[3] eq "1")?"selected":"";
			printf "<option %s value='2'>$text{'nobody'}\n", ($thlist[3] eq "2")?"selected":"";
			print "</select></td></tr>\n";
		}
		#print "<tr><td><input type=button name=removehostbtn value=\"$text{'remove'}\" onclick='' class=button1></td></tr>\n";
		print "</table></div></td>\n";
		#print "<td valign=top width=90><table class=mode1 border=0 cellspacing=8 cellpadding=1 width=100%>\n";
		#print "<tr><td align=center><input type=button name=addhostbtn value=\"$text{'add'}\" onclick='' class=button1></td></tr>\n";
		#print "<tr><td align=center><input type=button name=removehostbtn value=\"$text{'remove'}\" onclick='' class=button1></td></tr>\n";
		#print "</table></td>\n";
		print "<td valign=top><table class=mode1 border=0 cellspacing=4 cellpadding=1 width=100%>\n";
		#print "<tr><td colspan=2 class=title1>$text{'addnfshost'}</td></tr>\n";
		print "<tr><td><b>$text{'trusthost'}<b></td>\n";
		print "<td><select name=hosttype class=drop onchange='hosttypechange();'>\n";
		print "<option value='0'>$text{'everyone'}\n";
		print "<option value='1'>$text{'hosts'}\n";
		#print "<option value='2'>$text{'webnfs'}\n";
		print "<option value='3'>$text{'netgroup'}\n";
		print "<option value='4'>$text{'net_mask'}\n";
		print "</select></td></tr>\n";
		print "<tr><td></td><td><input name=nfshostin disabled=true class=disabletext size=15></td></tr>\n";
		print "<tr><td><b>$text{'accessmode'}</b></td>\n";
		print "<td><select name=accessmodesel class=drop>\n";
		print "<option value='0'>$text{'readonly'}\n";
		print "<option value='1'>$text{'readwrite'}\n";
		print "<option value='2'>$text{'denyaccess'}\n";
		print "</select></td></tr>\n";
		print "<tr><td><b>$text{'trustuser'}</b></td>\n";
		print "<td><select name=trustusersel class=drop>\n";
		print "<option value='0'>$text{'everyone'}\n";
		print "<option value='1'>$text{'exceptroot'}\n";
		print "<option value='2'>$text{'nobody'}\n";
		print "</select></td></tr>\n";
		print "<tr><td><input type=button name=addhostbtn value=\"$text{'add'}\" onclick='addnfstrustlist($n);' class=button1></td>\n";
		print "<td align=right><input type=button name=removehostbtn value=\"$text{'remove'}\" onclick='removenfstrustlist($n);' class=button1></td></tr>\n";
		print "</table></td> </tr>\n";
		print "</table><p>\n";
	}
	else
	{


		print "<input type=hidden name=trusthostcache value=\"$in{'trusthostcache'}\">\n";
	}
	if($in{'cat'} =~ /F/)
	{
		my @c_usertype = ($text{'local_user'}, $text{'local_group'}, $text{'pdc_user'}, $text{'pdc_group'});
		my ($ischecked, $is_disabled, @selectoption, %useracl, %btunit, $err_msg, @trustusers, $i, $n, @thlist, $needjoin, %idx);
		my (%u2d, %g2d, $dirname, @umsg, @gmsg, @file);

		$alertmsg = "asdf";

		$useracl{"0"} = $text{'readonly'};
		$useracl{"1"} = $text{'readwrite'};
		$btunit{"0"} = "KB";
		$btunit{"1"} = "MB";

		#table 1 user list
		print "<table class=tabpage cellpadding=1 cellspacing=0 width=100%>\n";
		print "<tr> <td valign=top width=50%><div class=small><table class=mode1 border=0 bordercolor=#33ccff cellspacing=0 cellpadding=1 width=100%>\n";
		#left table
		print "<tr> <td colspan=6>\n";
		print "<table class=mode1 width=100%>\n";
		print "<tr><td><b>$text{'ftp_access_usergroup'}</b></td>\n";
		@selectoption = ("<option value='name'>$text{'name'}\n", "<option value='accessmode'>$text{'accessmode'}\n", 
				 "<option value='usertype'>$text{'usertype'}\n", "<option value='ftp_ub_short'>$text{'ftp_ub_short'}\n",
				 "<option value='ftp_db_short'>$text{'ftp_db_short'}\n", 
				 "<option value='ftp_sessonperuser_short'>$text{'ftp_sessonperuser_short'}\n" );
		print "<td align=right><b>$text{'sort_with'}</b></td><td width=20><select name=ftp_sortuserlist onchange='RefreshPage();'>\n";
		for($i = 0; $i < @selectoption; $i++)
		{
		        if($selectoption[$i] =~ /<option value=\'$in{'ftp_sortuserlist'}\'>/)			
			{
			    $selectoption[$i] = "<option value=\'$in{'ftp_sortuserlist'}\' selected>$text{$in{'ftp_sortuserlist'}}\n";
			}
		}
		print @selectoption;
		print "</select>";
		print "</td></tr>\n";

		print "</table>\n";
		print "</td></tr>\n";
		print "<tr class=title1> <th align=left>$text{'name'}</th> ",
		"<th align=left>$text{'accessmode'}</th> ",
		"<th align=left>$text{'usertype'}</th> ",
		"<th align=left>$text{'ftp_ub_short'}</th> ",
		"<th align=left>$text{'ftp_db_short'}</th> ",
		"<th align=left>$text{'ftp_sessonperuser_short'}</th> ",
		"</tr>\n";

		@trustusers = split(":", $in{'trustftpusercache'});
#		@trustusers = sort {&get_list_elemt($a, $idx{$in{'ftp_sortuserlist'}}) cmp }
		&sort_ftp_userlist(\@trustusers, $in{'ftp_sortuserlist'});
		$n = @trustusers;		
		&foreign_require("pureftpd", "pureftpd-lib.pl");
		&foreign_call("pureftpd", "get_shareftp_u2d_g2d", \%u2d, \%g2d);

		&foreign_require("shareman", "shareman-lib.pl");
		&foreign_call("shareman", "read_sharetab", \%sharetab, 2);   #sharepath is key

		$n = 0;
		for ($i = 0; $i < @trustusers; $i++)
		{

			@thlist = split(',', $trustusers[$i]);

			if((($thlist[0] == 0) || ($thlist == 2)) && $u2d{$thlist[1]})
			{
				$dirname = $in{"sharepath"} . "/./";
				if($dirname ne $u2d{$thlist[1]})
				{
					$dirname = $u2d{$thlist[1]};
					$dirname =~ s/\/\.\/$//;  # delete '/./' in last dirname
					push @umsg, &text("msg_user_conflict", $thlist[1], $sharetab{$dirname}->{"sharename"});
					splice @trustusers, $i, 1;
					$i--;
					next;
				}
				
			}
			if((($thlist[0] == 1) || ($thlist == 3)) && $g2d{$thlist[1]})
			{
				$dirname = $in{"sharepath"} . "/./";
				if($dirname ne $g2d{$thlist[1]})
				{
					$dirname = $g2d{$thlist[1]};
					$dirname =~ s/\/\.\/$//;  # delete '/./' in last dirname
					push @umsg, &text("msg_group_conflict", $thlist[1], $sharetab{$dirname}->{"sharename"});
					splice @trustusers, $i, 1;
					$i--;
					next;
				}
			}

			$needjoin = 0;
			$err_msg = &check_input_num($thlist[3], $btunit{$thlist[4]});
			if($err_msg)
			{
				$thlist[3] = "0";
				$needjoin = 1;
			}

			$err_msg = &check_input_num($thlist[5], $btunit{$thlist[6]});

			if($err_msg)
			{
				$thlist[5] = "0";
				$needjoin = 1;
			}

			$err_msg = &check_input_not_integer($thlist[3]);
			if($err_msg)
			{
				if($thlist[3] > 0)
				{
					$thlist[3] = sprintf "%.2f", $thlist[3];
				}
				else
				{
					$thlist[3] = "0";
				}
				$needjoin = 1;
			}

			$err_msg = &check_input_not_integer($thlist[5]);
			if($err_msg)
			{
				if($thlist[5] > 0)
				{
					$thlist[5] = sprintf "%.2f", $thlist[5];
				}
				else
				{
					$thlist[5] = "0";
				}
				$needjoin = 1;
			}

			$err_msg = &check_input_not_integer($thlist[7]);
			if($err_msg)
			{
				$thlist[7] = "0";
				$needjoin = 1;
			}

			if ($n % 2 eq 1)
			{
				$dismode = "class=mode2";
			}
			else
			{
				$dismode = "class=mode1";
			}
			$n++;

			print "<tr $dismode> <td><input type=radio name=ftptrustrdn onclick=\'display_usermode(\"$thlist[2]\", \"$thlist[3]\", \"$thlist[4]\", \"$thlist[5]\", \"$thlist[6]\", \"$thlist[7]\");\'><input type=hidden name=ftpuseritem value='$thlist[0],$thlist[1]'>$thlist[1]</td>\n";
			print "<td>", $useracl{$thlist[2]}, "</td>\n";
			print "<td>$c_usertype[$thlist[0]]</td>\n";

			if($thlist[3])
			{
				print "<td>", $thlist[3], $btunit{$thlist[4]}, "</td>\n";
			}
			else
			{
				print "<td>$text{'nolimit'}</td>\n";
			}

			if($thlist[5])
			{
				print "<td>", $thlist[5], $btunit{$thlist[6]}, "</td>\n";
			}
			else
			{
				print "<td>$text{'nolimit'}</td>\n";
			}
			
			if($thlist[7])
			{
				print "<td>", $thlist[7], "</td></tr>\n";
			}
			else
			{
				print "<td>$text{'nolimit'}</td></tr>\n";
			}

			if($needjoin)
			{
				$trustusers[$i] = join(',', @thlist);
			}
		}

		print "</table></div></td>\n";
		$in{'trustftpusercache'} = join(':', @trustusers);
		print "<input type=hidden name=trustftpusercache value=\"$in{'trustftpusercache'}\">\n";

		splice @gmsg, 0, 0, @umsg if(@umsg > 0);
		$alertmsg = join('\n', @gmsg);


		#table 2 display user select
		print "<td valign=top width=200><table class=mode1 border=0 cellspacing=0 cellpadding=1 width=100%>\n";
		print "<tr> <td><b>$text{'allusers'}</b></td> </tr>\n";
		print "<tr> <td><select name=ftpusertyperdn onchange='ftpchange_user_list();'>\n";
		unless($in{'ftpusertyperdn'})
		{
			$in{'ftpusertyperdn'} = "0";
		}
		printf "<option %s value='0'>$text{'show_localuser'}\n", ($in{'ftpusertyperdn'} eq "0")?"selected":"";
		printf "<option %s value='1'>$text{'show_localgroup'}\n", ($in{'ftpusertyperdn'} eq "1")?"selected":"";
		#printf "<option %s value='2'>$text{'show_pdcuser'}\n", ($in{'ftpusertyperdn'} eq "2")?"selected":"";
		#printf "<option %s value='3'>$text{'show_pdcgroup'}\n", ($in{'ftpusertyperdn'} eq "3")?"selected":"";
		printf "</select></td></tr>\n";
		#print "<tr class=title1> <th align=left>$text{'usertype'}</th> ",
		#	"<th align=left>$text{'name'}</th> </tr>\n";
		#$n = 0;
		print "<tr> <td><select name=ftpuserslist size=10 class=list>\n";
		if ($in{'ftpusertyperdn'} eq "0")
		{
			open(LOCALUSER, $config{'localuser_file'});
			@file = <LOCALUSER>;
			close(LOCALUSER);

			for($i = @file - 1; $i >= 0; $i--)
			{
				chomp($file[$i]);
				$file[$i] =~ s/#.*$//;
				@line = split(':', $file[$i]);
				if($line[0])
				{
					$file[$i] = $line[0];
				}
				else
				{
					splice @file, $i, 1;
				}
			}

			@file = sort {$a cmp $b} @file;

			for($i = 0; $i < @file; $i++)
			{
				print "<option value=\'$file[$i]\'>$file[$i]\n";
			}
		}

		if ($in{'ftpusertyperdn'} eq "1")
		{
			open(LOCALGROUP, $config{'localgroup_file'});

			@file = <LOCALGROUP>;
			close(LOCALGROUP);

			for($i = @file - 1; $i >= 0; $i--)
			{
				chomp($file[$i]);
				$file[$i] =~ s/#.*$//;

				splice(@file, $i, 1) unless($file[$i]);
			}

			@file = sort {$a cmp $b} @file;

			for($i = 0; $i < @file; $i++)
			{
				print "<option value=\'$file[$i]\'>$file[$i]\n";
			}
		}

		if ($in{'ftpusertyperdn'} eq "2")
		{
			open(PDCUSER, $config{'pdcuser_file'});
			while ($line = <PDCUSER>) {
				$line =~ s/\r|\n//g;

			#print "<tr $dismode> <td><input type=radio name=alluserrdn value='2'>$text{'pdc_user'}</td>\n";
			#print "<td>$line</td> </tr>\n";
				print "<option value='$line'>$line\n";
			#$n ++;
			}
			close(PDCUSER);
		}

		if ($in{'ftpusertyperdn'} eq "3")
		{
			open(PDCGROUP, $config{'pdcgroup_file'});
			while ($line = <PDCGROUP>) {
				$line =~ s/\r|\n//g;

			#print "<tr $dismode> <td><input type=radio name=alluserrdn value='2'>$text{'pdc_user'}</td>\n";
			#print "<td>$line</td> </tr>\n";
				print "<option value='$line'>$line\n";
			#$n ++;
			}
			close(PDCGROUP);
		}
		print "</select></td> </tr>\n";

		print "</table></td> \n";

		#table 3 item propertiy
		unless($in{'ftp_ub'} > 0)
		{
			$in{'ftp_ub'} = 0;
		}

		unless($in{'ftp_db'} > 0)
		{
			$in{'ftp_db'} = 0;
		}

		unless($in{'sessionperuser'} > 0)
		{
			$in{'sessionperuser'} = 0;
		}

		print "<td width=30% valign=top><table border=0 class=mode1 width=100%> \n";
		print "<tr><td colspan=3><b>$text{'ftp_sharemode'}</b></td>\n";
		print "<tr><td>&nbsp;</td>\n";
		print "<tr><td width=55%><b>&nbsp;&nbsp;$text{'ftp_ub'}</b></td><td width=20%><input class=text size=6  name=ftp_ub value=\"$in{'ftp_ub'}\"></td><td>\n";
		@selectoption = ("<option value='0'>KB", "<option value='1'>MB");
		print "<select name=ub_unit size=1>";
		if($in{'ub_unit'} eq "0")
		{
			$selectoption[0] = "<option selected value='0'>KB";
		}
		if($in{'ub_unit'} eq "1")
		{
			$selectoption[1] = "<option selected value='1'>MB";
		}
		print @selectoption;
		print "</select>";
		print "</td></tr>\n";


		print "<tr><td><b>&nbsp;&nbsp;$text{'ftp_db'}</b></td><td><input class=text size=6 name=ftp_db value=\"$in{'ftp_db'}\"></td><td>\n";
		@selectoption = ("<option value='0'>KB", "<option value='1'>MB");
		print "<select name=db_unit size=1>";
		if($in{'db_unit'} eq "0")
		{
			$selectoption[0] = "<option selected value='0'>KB";
		}
		if($in{'db_unit'} eq "1")
		{
			$selectoption[1] = "<option selected value='1'>MB";
		}
		print @selectoption;
		print "</select>";
		print "</td></tr>\n";

		print "<tr><td><b>&nbsp;&nbsp;$text{'ftp_sessonperuser'}</b></td><td colspan=2><input class=text size=6 name=sessionperuser value=\"$in{'sessionperuser'}\"></td></tr>\n";
		print "<tr><td><b>&nbsp;&nbsp;$text{'ftp_accessmode'}</b></td><td colspan=2>\n";
		print "<select name=ftpaccesssel>\n";
		@selectoption = ("<option value='0'>$text{'readonly'}", "<option value='1'>$text{'readwrite'}");
		if($in{'ftpaccesssel'} eq "0")
		{
			$selectoption[0] = "<option selected value='0'>$text{'readonly'}";
		}
		if($in{'ftpaccesssel'} eq "1")
		{
			$selectoption[1] = "<option selected value='1'>$text{'readwrite'}";
		}
		print @selectoption;
		print "</select></td>\n";
		print "</td></tr>\n";

		#table 3_2 add/remove propertiry
		print "<tr><td colspan=3><table class=mode1 width=100%>";
		
		print "<tr><td width=33%><input type=button name=addftpuserbtn value=\"$text{'add'}\" onclick='addftptrustlist($n);' class=button1></td>\n";
		print "<td width=33%><input type=button name=removeftpuserbtn value=\"$text{'remove'}\" onclick='removeftptrustlist($n);' class=button1></td>\n";
		print "<td width=33%><input type=button name=removeftpuserbtn value=\"$text{'update'}\" onclick='updateftptrustlist($n);' class=button1></td>\n";
		print "</tr>";
		
		print "</table></td></tr>\n";

		print "</table></td>\n";

		print "</tr>\n";

		print "</table></div></td>\n";

		print "</table><p>\n";
	}
	else
	{
		print "<input type=hidden name=ftpusertyperdn value='$in{'ftpusertyperdn'}'>\n";
		print "<input type=hidden name=trustftpusercache value=\"$in{'trustftpusercache'}\">\n";
		print "<input type=hidden name=ftpaccesssel value=\"$in{'ftpaccesssel'}\">\n";
		print "<input type=hidden name=ftp_ub value=\"$in{'ftp_ub'}\">\n";
		print "<input type=hidden name=ftp_db value=\"$in{'ftp_db'}\">\n";
		print "<input type=hidden name=ub_unit value=\"$in{'ub_unit'}\">\n";
		print "<input type=hidden name=db_unit value=\"$in{'db_unit'}\">\n";
		print "<input type=hidden name=sessionperuser value=\"$in{'sessionperuser'}\">\n";
		print "<input type=hidden name=ftp_sortuserlist value=\"$in{'ftp_sortuserlist'}\">\n";
	}
	if($in{'cat'} =~ /H/)
	{

		print "<table class=tabpage cellpadding=1 cellspacing=0 width=100%>\n";

		print "<tr> <td><table class=mode1>\n";
		print "<tr> <td><b>$text{'need_auth'}</b></td>\n";
		printf "<td colspan=2><input type=radio name=needauthrdn %s value='y'>$text{'yes'}\n", ($in{'needauthrdn'} =~ 'y')?"checked":"";
		printf "<input type=radio name=needauthrdn %s value='n'>$text{'no'}</td> </tr>\n", ($in{'needauthrdn'} =~ 'n')?"checked":"";
		print "<tr> <td><b>$text{'access_by_login'}</b></td>\n";
		printf "<td colspan=2><input type=radio name=accessloginrdn %s value='0'>$text{'all_users'}</td>\n", ($in{'accessloginrdn'} =~ /0/)?"checked":"";
		printf "<tr> <td></td><td><input type=radio name=accessloginrdn %s value='1'>$text{'only_users'}</td><td><input name=onlyusersin size=40 value='$in{'onlyusersin'}' class=text> %s</td></tr>\n", ($in{'accessloginrdn'} =~ /1/)?"checked":"", &ezstor_local_user_chooser_button("onlyusersin", 1);
		printf "<tr> <td></td><td><input type=radio name=accessloginrdn %s value='2'>$text{'only_groups'}</td><td><input name=onlygroupsin size=40 value='$in{'onlygroupsin'}' class=text> %s</td></tr>\n", ($in{'accessloginrdn'} =~ /2/)?"checked":"", &ezstor_local_group_chooser_button("onlygroupsin", 1);
		print "</table></td></tr>\n";
		print "</table><p>\n";

	}
	else
	{
		print "<input type=hidden name=needauthrdn value='$in{'needauthrdn'}'>\n";

		print "<input type=hidden name=accessloginrdn value='$in{'accessloginrdn'}'>\n";
		print "<input type=hidden name=onlyusersin value='$in{'onlyusersin'}'>\n";
		print "<input type=hidden name=onlygroupsin value='$in{'onlygroupsin'}'>\n";

	}

	if ($in{'cat'} =~ /A/)
	{
		my @file, @line, $i;
		my @c_usertype = ($text{'local_user'}, $text{'local_group'}, $text{'pdc_user'}, $text{'pdc_group'});

		print "<table class=tabpage cellpadding=5 cellspacing=0 width=100% border=0>\n";
		
		#ulist table 1
		print "<tr> <td valign=top width=40%><div class=small><table class=mode1 border=0 cellspacing=0 cellpadding=1 width=100%>\n";
		print "<tr> <td colspan=3><b>$text{'trustedusers'}</b></td></tr>\n";
		print "<tr class=title1> <th align=left>$text{'name'}</th> ",
			"<th align=left>$text{'accessmode'}</th> ",
			"<th align=left>$text{'usertype'}</th> </tr>\n";
		@trustusers = split(":", $in{'afptrustusercache'});
		&sort_afp_uglist(\@trustusers, "name");
		$n = @trustusers;		
		for ($i = 0; $i < @trustusers; $i ++)
		{
			if ($i % 2 eq 1)
			{
				$dismode = "class=mode2";
			}
			else
			{
				$dismode = "class=mode1";
			}
			my @thlist = split(',', $trustusers[$i]);
			print "<tr $dismode> <td><input type=radio name=afptrustrdn><input type=hidden name=afpuseritem value='$thlist[0],$thlist[1]'>$thlist[1]</td>\n";


			print "<td><select name=afpaccessitem class=drop onchange='cacheafplist($n)'>\n";
			printf "<option %s value='ro'>$text{'readonly'}\n", ($thlist[2] eq "ro")?"selected":"";
			printf "<option %s value='rw'>$text{'readwrite'}\n", ($thlist[2] eq "rw")?"selected":"";
			printf "<option %s value='dy'>$text{'denyaccess'}\n", ($thlist[2] eq "dy")?"selected":"";
			print "</select></td>\n";
			print "<td>$c_usertype[$thlist[0]]</td> </tr>\n";
		}

		print "</table></div></td>\n";
		$in{'afptrustusercache'} = join(":", @trustusers);
		print "<input type=hidden name=afptrustusercache value=\"$in{'afptrustusercache'}\">\n";

		#access mode table 2
		print "<td width = 10%><table class=mode1 border=0 cellspacing=8 cellpadding=1 width=100%>\n";
		print "<tr> <td align=center><b>$text{'accessmode'}</b>\n";
		print "<select name=afpaccesssel>\n";
		printf "<option %s value='ro'>$text{'readonly'}\n", ($in{'afpaccesssel'} eq "ro")?"selected":"";
		printf "<option %s value='rw'>$text{'readwrite'}\n", ($in{'afpaccesssel'} eq "rw")?"selected":"";
		printf "<option %s value='dy'>$text{'denyaccess'}\n", ($in{'afpaccesssel'} eq "dy")?"selected":"";
		print "</select></td> </tr>\n";
		print "<tr><td align=center><input type=button name=addafpuserbtn value=\"$text{'add'}\" onclick='addafptrustlist($n);' class=button1></td> </tr>\n";
		print "<tr> <td align=center><input type=button name=removeafpuserbtn value=\"$text{'remove'}\" onclick='removeafptrustlist($n);' class=button1></td></tr>\n";
		print "</table></td>\n";

		#localuser select table       table 3
		print "<td valign=top width=200><table class=mode1 border=0 cellspacing=0 cellpadding=1 width=100%>\n";
		print "<tr> <td><b>$text{'allusers'}</b></td> </tr>\n";
		print "<tr> <td><select name=afpusertyperdn onchange='afp_change_user_list();'>\n";
		printf "<option %s value='0'>$text{'show_localuser'}\n", ($in{'afpusertyperdn'} eq "0")?"selected":"";
		printf "<option %s value='1'>$text{'show_localgroup'}\n", ($in{'afpusertyperdn'} eq "1")?"selected":"";
		printf "</select></td></tr>\n";
		#print "<tr class=title1> <th align=left>$text{'usertype'}</th> ",
		#	"<th align=left>$text{'name'}</th> </tr>\n";
		#$n = 0;
		unless($in{'afpusertyperdn'})
		{
			$in{'afpusertyperdn'} = 0;
		}

		print "<tr> <td><select name=afpuserslist size=10 class=list>\n";
		if ($in{'afpusertyperdn'} eq "0")
		{
			open(LOCALUSER, $config{'localuser_file'});
			@file = <LOCALUSER>;
			close(LOCALUSER);

			for($i = @file - 1; $i >= 0; $i--)
			{
				chomp($file[$i]);
				$file[$i] =~ s/#.*$//;
				@line = split(':', $file[$i]);
				if($line[0])
				{
					$file[$i] = $line[0];
				}
				else
				{
					splice @file, $i, 1;
				}
			}

			@file = sort {$a cmp $b} @file;

			for($i = 0; $i < @file; $i++)
			{
				print "<option value=\'$file[$i]\'>$file[$i]\n";
			}
		}

		if ($in{'afpusertyperdn'} eq "1")
		{
			open(LOCALGROUP, $config{'localgroup_file'});

			@file = <LOCALGROUP>;
			close(LOCALGROUP);

			for($i = @file - 1; $i >= 0; $i--)
			{
				chomp($file[$i]);
				$file[$i] =~ s/#.*$//;

				splice(@file, $i, 1) unless($file[$i]);
			}

			@file = sort {$a cmp $b} @file;

			for($i = 0; $i < @file; $i++)
			{
				print "<option value=\'$file[$i]\'>$file[$i]\n";
			}
		}

		print "</select></td> </tr>\n";

		print "</table></td>\n";

		print "<td valign=top>";
		print "<table class=mode1>\n";

		print "<tr><td colspan=2><b>$text{'afp_property'}</b></td></tr>\n";
		print "<tr><td colspan=2>&nbsp;</td></tr>\n";
		printf "<tr><td><input type=checkbox name=afp_allowguest value='yes' %s ></td><td>$text{'afp_allowguest'}</td></tr>\n", $in{'afp_allowguest'} eq 'yes'?'checked':'';
		printf "<tr><td><input type=checkbox name=afp_mountRO value='yes' %s ></td><td>$text{'afp_mountRO'}</td></tr>\n", $in{'afp_mountRO'} eq 'yes'?'checked':'';
#		printf "<tr><td><input type=checkbox name=afp_setVolumePasswd value='yes' %s onclick='afp_clk_setpasswd(this)'></td><td>$text{'afp_setVolumePasswd'}</td></tr>\n", $in{'afp_setVolumePasswd'} eq 'yes'?'checked':'';
#		printf "<tr><td></td><td>$text{'afp_passwd'}<input name=afp_passwd size=12 type=password %s value=\'$in{'afp_passwd'}\'></td></tr>\n", $in{'afp_setVolumePasswd'} eq 'yes'?'class=text':'class=disabletext disabled=true';
#		print "<tr><td></td><td>$text{'afp_passwd'}<input name=afp_passwd size=12 class=text type=password value=\'$in{'afp_passwd'}\'></td></tr>\n";

		print "</table></td>\n";

		print "</tr>\n";

		

		print "</table><p>\n";
	}
	else
	{
		print "<input type=hidden name=afpusertyperdn value=\"$in{'afpusertyperdn'}\">\n";
		print "<input type=hidden name=afptrustusercache value=\"$in{'afptrustusercache'}\">\n";
		print "<input type=hidden name=afpaccesssel value=\"$in{'afpaccesssel'}\">\n";
		print "<input type=hidden name=afp_allowguest value=\"$in{'afp_allowguest'}\">";
		print "<input type=hidden name=afp_mountRO value=\"$in{'afp_mountRO'}\">";
#		print "<input type=hidden name=afp_setVolumePasswd value=\"$in{'afp_setVolumePasswd'}\">";
#		print "<input type=hidden name=afp_passwd value=\"$in{'afp_passwd'}\">";
	}

	print "<input type=submit name=saveshare value='$text{'submit'}' onclick='return setupactionstatus();' class=button1>\n";
	print "</form>\n";
}


if ($emode eq 'delete')
{
#	&header($text{'create_share_title'}, "", undef, 0, 1);
	my @sinfo = &search_shareinfo($spath);
	#print @sinfo;
	if(@sinfo)
	{
		if ($sinfo[1] =~ /W/)
		{
			if (&check_cifs_config($sinfo[0]))
			{
				&foreign_require("samba", "samba-lib.pl");
				%econfig = &foreign_config("samba");
				&lock_file($econfig{'smb_conf'});
				@exps = &foreign_call("samba", "list_shares");
				foreach $s (@exps) {
					&foreign_call("samba", "get_share", $s);
					if (&foreign_call("samba", "getval", "copy") eq $sinfo[0])
					{
						&foreign_call("samba", "delete_share", $s);
					}
				}
				&foreign_call("samba", "delete_share", $sinfo[0]);

				&unlock_file($econfig{'smb_conf'});
				&nas_syslog("shareman", "naslog_info", 31000, "Delete cifs share success!");
			}
			`$config{'cifs_reload'}`;
		}
		if ($sinfo[1] =~ /U/)
		{
			my @chknfs = &check_nfs_config($spath);
			#print @chknfs;
			if ($chknfs[0])
			{
				splice(@chknfs, 0, 1);
				&foreign_require("exports", "exports-lib.pl");
				%econfig = &foreign_config("exports");
				&lock_file($econfig{'exports_file'});
				&delete_export_by_indexes(\@chknfs);
				&unlock_file($econfig{'exports_file'});
				&nas_syslog("shareman", "naslog_info", 31001, "Delete nfs share success!");
			}
			`$config{'nfs_reload'}`;
		}
		if ($sinfo[1] =~ /F/)
		{
			my (%pw, %sd, %gp);
			&foreign_require("pureftpd", "pureftpd-lib.pl");
			&foreign_call("pureftpd","get_pw_hash", \%pw);
			&foreign_call("pureftpd","get_sd_hash", \%sd);
			&foreign_call("pureftpd","get_gp_hash", \%gp);
			
			&foreign_call("pureftpd", "fetch_ftp_dir", $spath);

			&foreign_call("pureftpd", "share_ftp_reload", \%sd, \%pw, \%gp);
			&foreign_call("pureftpd", "sync_ftppasswd_with_getent", \%sd, \%pw);
			&foreign_call("pureftpd", "sync_ftpgroup_with_getent", \%gp);

			`$config{'ftp_reload'}`;
		}
		if ($sinfo[1] =~ /H/)
		{
			my @chkhttp = &check_http_config($sinfo[0], $spath);
			if ($chkhttp[0])
			{
				&foreign_require("apache", "apache-lib.pl");
				my $d = $chkhttp[3];
				$f = $d->{'file'};
				&lock_file($f);
				my $lref = &read_file_lines($f);
				splice(@$lref, $d->{'line'}, $d->{'eline'}-$d->{'line'}+1);
				&flush_file_lines();
				&unlock_file($f);
				&nas_syslog("shareman", "naslog_info", 31003, "Delete http share success!");
			}
			$droot = $chkhttp[2];
#			`rm -f $droot\/$sinfo[0]`;
			ez_system("rm", "-f", $droot."\/".$sinfo[0]);
			`$config{'http_reload'}`;
		}
		if ($sinfo[1] =~ /A/)
		{
			&afp_del($spath);
			#`$config{'afp_reload'}`;
		}
	}
	&save_sharetab(2, $spath);
	redirect("index.cgi");
}

print <<EOF;
<script>
function afp_clk_setpasswd(obj)
{
        if(obj.checked)
        {
                 document.forms[0].afp_passwd.value = "";
                 document.forms[0].afp_passwd.style.backgroundColor = "#ffffff";
                 document.forms[0].afp_passwd.disabled = false;
        }
        else
        {
                 document.forms[0].afp_passwd.value = "";
                 document.forms[0].afp_passwd.style.backgroundColor = "#d4d0c8";
                 document.forms[0].afp_passwd.disabled = true;
        }
}

function removeafptrustlist(n)
{
	var found = -1;
        var useritemarray;
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].afptrustrdn.length; i++)
		{
			if (document.forms[0].afptrustrdn[i].checked)
			{
				found = i;
				break;
			}
		}
	}
	else if (n == 1)
	{
		if (document.forms[0].afptrustrdn.checked)
		{
			found = 0;
		}
	}
	if (found >= 0)
	{
		useritemarray =document.forms[0].afptrustusercache.value.split(":");
                document.forms[0].afptrustusercache.value = "";
		if (n > 1)
		{
			for (i = 0; i < useritemarray.length; i++)
			{
				if (i != found)
                                {
                                        if(document.forms[0].afptrustusercache.value != "")
                                        {
                                                 document.forms[0].afptrustusercache.value += ":";
                                        }
                                        document.forms[0].afptrustusercache.value += useritemarray[i];
                                }
			}
		}
		RefreshPage();
	}
	else
	{
		alert("$text{'noselecttrustuser'}");
	}
}

function cacheafplist(n)
{
	document.forms[0].afptrustusercache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].afptrustrdn.length; i++)
		{
			document.forms[0].afptrustusercache.value +=(document.forms[0].afpuseritem[i].value +","+
							document.forms[0].afpaccessitem[i].value);
			if (i < (document.forms[0].afptrustrdn.length - 1))
				document.forms[0].afptrustusercache.value += ":";
		}
	}
	else if (n == 1)
	{
		document.forms[0].afptrustusercache.value +=(document.forms[0].afpuseritem.value +","+
							document.forms[0].afpaccessitem.value);
	}
}

function addafptrustlist(n)
{
	var idx = document.forms[0].afpuserslist.selectedIndex;
        var i, find;
        var uitem;

        find = 0;
	if (idx < 0)
	{
		alert("$text{'noselectcifsuser'}");
		return;
	}
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].afptrustrdn.length; i++)
		{
                        if(!find)
                        {
                                 uitem = (document.forms[0].afpusertyperdn.value +","+ document.forms[0].afpuserslist.value);
                                 if(document.forms[0].afpuseritem[i].value == uitem)
                                 {
                                         find = 1;
                                 }
                        }
		}
	}
	else if (n == 1)
	{
                if(!find)
                {
                        uitem = (document.forms[0].afpusertyperdn.value +","+ document.forms[0].afpuserslist.value);
                        if(document.forms[0].afpuseritem.value == uitem)
                        {
                                 find = 1;
                        }
                }
	}

        if(find == 1)
        {
                alert("$text{'msg_item_exist'}");
                return false;
        }

        if(document.forms[0].afptrustusercache.value != "")
        {
                document.forms[0].afptrustusercache.value += ":";
        }

	document.forms[0].afptrustusercache.value +=(document.forms[0].afpusertyperdn.value +","+
							document.forms[0].afpuserslist.value +"," +
							document.forms[0].afpaccesssel.value);

	RefreshPage();
}

function afp_change_user_list()
{
	RefreshPage();
}

function display_usermode(acl, ftp_ub, ub_unit, ftp_db, db_unit, sessionperuser)
{
	document.forms[0].ftpaccesssel.selectedIndex = acl;
	document.forms[0].ftp_ub.value = ftp_ub;
	document.forms[0].ub_unit.selectedIndex = ub_unit;
	document.forms[0].ftp_db.value = ftp_db;
	document.forms[0].db_unit.selectedIndex = db_unit;
	document.forms[0].sessionperuser.value = sessionperuser;
}

function updateftptrustlist(n)
{
	var found = -1;
        var useritemarray;
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].ftptrustrdn.length; i++)
		{
			if (document.forms[0].ftptrustrdn[i].checked)
			{
				found = i;
				break;
			}
		}
	}
	else if (n == 1)
	{
		if (document.forms[0].ftptrustrdn.checked)
		{
			found = 0;
		}
	}
	if (found >= 0)
	{
		useritemarray =document.forms[0].trustftpusercache.value.split(":");
                if(n > 1)
                {
                        useritemarray[found] = (document.forms[0].ftpuseritem[found].value + "," +
							document.forms[0].ftpaccesssel.value + "," +
							document.forms[0].ftp_ub.value + "," +
							document.forms[0].ub_unit.value + "," + 
							document.forms[0].ftp_db.value + "," +
							document.forms[0].db_unit.value + "," +
							document.forms[0].sessionperuser.value);
                }
                else
                {
                        useritemarray[found] = (document.forms[0].ftpuseritem.value + "," +
							document.forms[0].ftpaccesssel.value + "," +
							document.forms[0].ftp_ub.value + "," +
							document.forms[0].ub_unit.value + "," + 
							document.forms[0].ftp_db.value + "," +
							document.forms[0].db_unit.value + "," +
							document.forms[0].sessionperuser.value);
                }
                document.forms[0].trustftpusercache.value = "";
                if(n > 1)
                {
		        for (i = 0; i < useritemarray.length; i++)
		        {
                                if(document.forms[0].trustftpusercache.value != "")
                                {
                                        document.forms[0].trustftpusercache.value += ":";
                                }
                                document.forms[0].trustftpusercache.value += useritemarray[i];
                        }
		}
                else
                {
                        document.forms[0].trustftpusercache.value += useritemarray;
                }
		RefreshPage();
	}
	else
	{
		alert("$text{'noselecttrustuser'}");
	}
}

function cacheftplist(n)
{
	document.forms[0].trustftpusercache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].ftptrustrdn.length; i++)
		{
			document.forms[0].trustftpusercache.value +=(document.forms[0].ftpuseritem[i].value +","+
							document.forms[0].ftpaccessitem[i].value);
			if (i < (document.forms[0].ftptrustrdn.length - 1))
				document.forms[0].trustftpusercache.value += ":";
		}
	}
	else if (n == 1)
	{
		document.forms[0].trustftpusercache.value +=(document.forms[0].ftpuseritem.value +","+
							document.forms[0].ftpaccessitem.value);
	}
}

function addftptrustlist(n)
{
	var idx = document.forms[0].ftpuserslist.selectedIndex;
        var i, find;
        var uitem;

        find = 0;
	if (idx < 0)
	{
		alert("$text{'noselectcifsuser'}");
		return;
	}
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].ftptrustrdn.length; i++)
		{
                        if(!find)
                        {
                                 uitem = (document.forms[0].ftpusertyperdn.value +","+ document.forms[0].ftpuserslist.value);
                                 if(document.forms[0].ftpuseritem[i].value == uitem)
                                 {
                                         find = 1;
                                 }
                        }
		}
	}
	else if (n == 1)
	{
                if(!find)
                {
                        uitem = (document.forms[0].ftpusertyperdn.value +","+ document.forms[0].ftpuserslist.value);
                        if(document.forms[0].ftpuseritem.value == uitem)
                        {
                                 find = 1;
                        }
                }
	}

        if(find == 1)
        {
                alert("$text{'msg_item_exist'}");
                return false;
        }

        if(document.forms[0].trustftpusercache.value != "")
        {
                document.forms[0].trustftpusercache.value += ":";
        }

	document.forms[0].trustftpusercache.value +=(document.forms[0].ftpusertyperdn.value +","+
							document.forms[0].ftpuserslist.value +"," +
							document.forms[0].ftpaccesssel.value + "," +
							document.forms[0].ftp_ub.value + "," +
							document.forms[0].ub_unit.value + "," + 
							document.forms[0].ftp_db.value + "," +
							document.forms[0].db_unit.value + "," +
							document.forms[0].sessionperuser.value);
	RefreshPage();
}

function removeftptrustlist(n)
{
	var found = -1;
        var useritemarray;
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].ftptrustrdn.length; i++)
		{
			if (document.forms[0].ftptrustrdn[i].checked)
			{
				found = i;
				break;
			}
		}
	}
	else if (n == 1)
	{
		if (document.forms[0].ftptrustrdn.checked)
		{
			found = 0;
		}
	}
	if (found >= 0)
	{
		useritemarray =document.forms[0].trustftpusercache.value.split(":");
                document.forms[0].trustftpusercache.value = "";
		if (n > 1)
		{
			for (i = 0; i < useritemarray.length; i++)
			{
				if (i != found)
                                {
                                        if(document.forms[0].trustftpusercache.value != "")
                                        {
                                                 document.forms[0].trustftpusercache.value += ":";
                                        }
                                        document.forms[0].trustftpusercache.value += useritemarray[i];
                                }
			}
		}
		RefreshPage();
	}
	else
	{
		alert("$text{'noselecttrustuser'}");
	}
}

function ftpchange_user_list()
{
	RefreshPage();
}


function CheckShareParam()
{
	var i;
	checktype = false;
	if (document.forms[0].sharename.value == '')
		return false;
	if (document.forms[0].sharepath.value == '')
		return false;
	for (i = 0; i<4; i++)
	{
		if (document.forms[0].sharetype[i].checked)
			checktype = true;
	}
	return checktype;
}

function change_user_list()
{
	RefreshPage();
}

function RefreshPage()
{
	document.forms[0].action = 'edit_share.cgi';
	document.forms[0].submit();
}

function addhostentry()
{
	if (document.forms[0].exporthost[0].checked)
	{
		hostentry = "0,";
		entrytext = "$text{'everyone'}" + " ";
	}
	if (document.forms[0].exporthost[1].checked)
	{
		hostentry = "1," +document.forms[0].hostin.value;
		entrytext = "$text{'hosts'}" + " "+document.forms[0].hostin.value + " ";
	}
	if (document.forms[0].exporthost[2].checked)
	{
		hostentry = "2,";
		entrytext = "$text{'webnfs'}" + " ";
	}
	if (document.forms[0].exporthost[3].checked)
	{
		hostentry = "3," + document.forms[0].netgroupin.value;
		entrytext = "$text{'netgroup'}" + " " +document.forms[0].netgroupin.value+ " ";
	}
	if (document.forms[0].exporthost[4].checked)
	{
		hostentry = "4," + document.forms[0].netmaskin.value;
		entrytext = "$text{'network'}" + " " +document.forms[0].netmaskin.value+ " ";
	}
	hostentry +=",n,1,n,1";
	entrytext += "$text{'readwrite'}";
	i = document.forms[0].hostlist.options.length;
	document.forms[0].hostlist.options[i] = new Option(entrytext, hostentry);
	cachehostlist();
	document.forms[0].exporthost[0].checked = true;
	document.forms[0].hostin.value = "";
	document.forms[0].netgroupin.value = "";
	document.forms[0].netmaskin.value = "";
	//document.forms[0].submit();
}

function cachehostlist()
{
	var str ="";
	for (i = 0; i < document.forms[0].hostlist.options.length; i++)
	{
		str += document.forms[0].hostlist.options[i].text + ":" + document.forms[0].hostlist.options[i].value + ":";
		//if (i < (document.forms[0].hostlist.options.length -1))
		//	str +=":";
	}
	str += document.forms[0].hostlist.selectedIndex;
	document.forms[0].hostlistcache.value = str;
}

function removehostentry()
{
	var idx = document.forms[0].hostlist.selectedIndex;

	if ( idx >= 0)
	{
		if (document.forms[0].hostlist.options.length == 1)
		{
			alert("$text{'not_empty'}");
		}
		else
		{
			document.forms[0].hostlist.options[idx] = null;
			cachehostlist();
		}
	}
}

function hostselectchange()
{
	var idx = document.forms[0].hostlist.selectedIndex;
	if (idx >=0)
	{
		var opstr = document.forms[0].hostlist.options[idx].value;
		strarrays = opstr.split(",");
		if (strarrays[2] == "y")
			document.forms[0].linkradio[0].checked = true;
		else
			document.forms[0].linkradio[1].checked = true;
		if (strarrays[3] == "0")
			document.forms[0].accessmd[0].checked = true;
		else
			document.forms[0].accessmd[1].checked = true;
		if (strarrays[4] == "y")
			document.forms[0].denymd[0].checked = true;
		else
			document.forms[0].denymd[1].checked = true;
		if (strarrays[5] == "0")
			document.forms[0].trustmd[0].checked = true;
		else if(strarrays[5] == "1")
			document.forms[0].trustmd[1].checked = true;
		else
			document.forms[0].trustmd[2].checked = true;
	}
	cachehostlist();

}

function change_param()
{
	var idx = document.forms[0].hostlist.selectedIndex;
	if (idx >=0)
	{
		var tempvalue = document.forms[0].hostlist.options[idx].value;
		strarray = tempvalue.split(",");
		tempvalue = strarray[0]+","+strarray[1] + ",";
		if (strarray[0] == '0')
			temptext = "$text{'everyone'}" +" "+strarray[1]+ " ";
		else if (strarray[0] == '1')
			temptext = "$text{'hosts'}" +" "+strarray[1]+ " ";
		else if (strarray[0] == '2')
			temptext = "$text{'webnfs'}" +" "+strarray[1]+ " ";
		else if (strarray[0] == '3')
			temptext = "$text{'netgroup'}" +" "+strarray[1]+ " ";
		else
			temptext = "$text{'network'}" +" "+strarray[1]+ " ";
		tempvalue += (document.forms[0].linkradio[0].checked)?"y,":"n,";
		tempvalue += (document.forms[0].accessmd[0].checked)?"0,":"1,";
		temptext += (document.forms[0].accessmd[0].checked)?"$text{'readonly'}":"$text{'readwrite'}";
		tempvalue += (document.forms[0].denymd[0].checked)?"y,":"n,";
		temptext += (document.forms[0].denymd[0].checked)?" $text{'denyaccess'}":"";
		if (document.forms[0].trustmd[0].checked)
			tempvalue +="0";
		else if (document.forms[0].trustmd[1].checked)
			tempvalue +="1";
		else
			tempvalue +="2";
		document.forms[0].hostlist.options[idx].value = tempvalue;
		document.forms[0].hostlist.options[idx].text = temptext;
	}
	cachehostlist();
}

function setupactionstatus()
{
	document.forms[0].action = 'save_share.cgi';
}

function change_category(s)
{
	document.forms[0].cat.value = s;
	RefreshPage();
}

function addnfstrustlist(n)
{
        var i, find, hitem;

        find = 0;
        hitem = "";

	document.forms[0].trusthostcache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].nfshostrdn.length; i++)
		{
			document.forms[0].trusthostcache.value +=(document.forms[0].hostitem[i].value +","+
							document.forms[0].accessmodeitem[i].value +"," +
							document.forms[0].trustuseritem[i].value + ":");

                        if(!find)
                        {
                                 hitem = (document.forms[0].hosttype.value +","+ document.forms[0].nfshostin.value);
                                 if(document.forms[0].hostitem[i].value == hitem)
                                 {
                                         find = 1;
                                 }
                        }
		}
	}

	else if (n == 1)
	{
		document.forms[0].trusthostcache.value +=(document.forms[0].hostitem.value +","+
							document.forms[0].accessmodeitem.value +"," +
							document.forms[0].trustuseritem.value + ":");
                if(!find)
                {
                        hitem = (document.forms[0].hosttype.value +","+ document.forms[0].nfshostin.value);
                        if(document.forms[0].hostitem.value == hitem)
                        {
                                 find = 1;
                        }
                }
	}
        if(find == 1)
        {
                alert("$text{'msg_item_exist'}");
                return false;
        }

	document.forms[0].trusthostcache.value +=(document.forms[0].hosttype.value +","+
							document.forms[0].nfshostin.value +"," +
							document.forms[0].accessmodesel.value + "," +
							document.forms[0].trustusersel.value);
	document.forms[0].hosttype.value = 0;
	document.forms[0].nfshostin.value = "";
	document.forms[0].accessmodesel.value = 0;
	document.forms[0].trustusersel.value = 0;
	RefreshPage();
}

function removenfstrustlist(n)
{
	var found = -1;
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].nfshostrdn.length; i++)
		{
			if (document.forms[0].nfshostrdn[i].checked)
			{
				found = i;
				break;
			}
		}
	}
	else if (n == 1)
	{
		if (document.forms[0].nfshostrdn.checked)
		{
			found = 0;
			alert("$text{'not_empty'}");
			return;
		}
	}
	if (found >= 0)
	{
		document.forms[0].trusthostcache.value = "";
		if (n > 1)
		{
			for (i = 0; i < document.forms[0].nfshostrdn.length; i++)
			{
				if (i != found)
					document.forms[0].trusthostcache.value +=(document.forms[0].hostitem[i].value +","+
							document.forms[0].accessmodeitem[i].value +"," +
							document.forms[0].trustuseritem[i].value + ":");
			}
		}
		RefreshPage();
	}
	else
	{
		alert("$text{'noselectnfshost'}");
	}
}

function cachenfslist(n)
{
	document.forms[0].trusthostcache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].nfshostrdn.length; i++)
		{
			document.forms[0].trusthostcache.value +=(document.forms[0].hostitem[i].value +","+
							document.forms[0].accessmodeitem[i].value +"," +
							document.forms[0].trustuseritem[i].value);
			if (i < (document.forms[0].nfshostrdn.length - 1))
				document.forms[0].trusthostcache.value += ":";
		}
	}
	else if (n == 1)
	{
		document.forms[0].trusthostcache.value +=(document.forms[0].hostitem.value +","+
							document.forms[0].accessmodeitem.value +"," +
							document.forms[0].trustuseritem.value);
	}
}

function hosttypechange()
{
	if ((document.forms[0].hosttype.value == '0')||(document.forms[0].hosttype.value == '2'))
	{
		document.forms[0].nfshostin.disabled = true;
		document.forms[0].nfshostin.value = "";
		document.forms[0].nfshostin.style.backgroundColor = "#d4d0c8";
	}
	else
	{
		document.forms[0].nfshostin.disabled = false;
		document.forms[0].nfshostin.style.backgroundColor = "#ffffff";
	}
}

function addcifstrustlist(n)
{
	var idx = document.forms[0].userslist.selectedIndex;
        var i, find;
        var uitem;

        find = 0;
	if (idx < 0)
	{
		alert("$text{'noselectcifsuser'}");
		return;
	}
	document.forms[0].trustusercache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].cifstrustrdn.length; i++)
		{
			document.forms[0].trustusercache.value +=(document.forms[0].cifsuseritem[i].value +","+
							document.forms[0].cifsaccessitem[i].value + ":");
                        if(!find)
                        {
                                 uitem = (document.forms[0].usertyperdn.value +","+ document.forms[0].userslist.value);
                                 if(document.forms[0].cifsuseritem[i].value == uitem)
                                 {
                                         find = 1;
                                 }
                        }
		}
	}
	else if (n == 1)
	{
		document.forms[0].trustusercache.value +=(document.forms[0].cifsuseritem.value +","+
							document.forms[0].cifsaccessitem.value + ":");
                if(!find)
                {
                        uitem = (document.forms[0].usertyperdn.value +","+ document.forms[0].userslist.value);
                        if(document.forms[0].cifsuseritem.value == uitem)
                        {
                                 find = 1;
                        }
                }
	}

        if(find == 1)
        {
                alert("$text{'msg_item_exist'}");
                return false;
        }

	document.forms[0].trustusercache.value +=(document.forms[0].usertyperdn.value +","+
							document.forms[0].userslist.value +"," +
							document.forms[0].cifsaccesssel.value);


	RefreshPage();
}

function removecifstrustlist(n)
{
	var found = -1;
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].cifstrustrdn.length; i++)
		{
			if (document.forms[0].cifstrustrdn[i].checked)
			{
				found = i;
				break;
			}
		}
	}
	else if (n == 1)
	{
		if (document.forms[0].cifstrustrdn.checked)
		{
			found = 0;
		}
	}
	if (found >= 0)
	{
		document.forms[0].trustusercache.value = "";
		if (n > 1)
		{
			for (i = 0; i < document.forms[0].cifstrustrdn.length; i++)
			{
				if (i != found)
					document.forms[0].trustusercache.value +=(document.forms[0].cifsuseritem[i].value +","+
							document.forms[0].cifsaccessitem[i].value + ":");
			}
		}
		RefreshPage();
	}
	else
	{
		alert("$text{'noselecttrustuser'}");
	}
}

function cachecifslist(n)
{
	document.forms[0].trustusercache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].cifstrustrdn.length; i++)
		{
			document.forms[0].trustusercache.value +=(document.forms[0].cifsuseritem[i].value +","+
							document.forms[0].cifsaccessitem[i].value);
			if (i < (document.forms[0].cifstrustrdn.length - 1))
				document.forms[0].trustusercache.value += ":";
		}
	}
	else if (n == 1)
	{
		document.forms[0].trustusercache.value +=(document.forms[0].cifsuseritem.value +","+
							document.forms[0].cifsaccessitem.value);
	}
}

function addtoaccesslist(n)
{
	document.forms[0].restrictlistcache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].accessaction.length; i++)
		{
			document.forms[0].restrictlistcache.value +=(document.forms[0].accessaction[i].value +","+
							document.forms[0].accesscondition[i].value +"," +
							document.forms[0].accessin[i].value + ":");
		}
	}
	else if (n == 1)
	{
		document.forms[0].restrictlistcache.value +=(document.forms[0].accessaction.value +","+
							document.forms[0].accesscondition.value +"," +
							document.forms[0].accessin.value + ":");
	}
	document.forms[0].restrictlistcache.value +=(document.forms[0].actionadd.value +","+
							document.forms[0].conditionadd.value +"," +
							document.forms[0].conditionaddin.value);
	document.forms[0].actionadd.value = 0;
	document.forms[0].conditionadd.value = 0;
	document.forms[0].conditionaddin.value = "";
	RefreshPage();
}

function removefromaccesslist(n)
{
	var found = -1;
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].accessaction.length; i++)
		{
			if (document.forms[0].selectitem[i].checked)
			{
				found = i;
				break;
			}
		}
	}
	else if (n == 1)
	{
		if (document.forms[0].selectitem.checked)
		{
			found = 0;
		}
	}
	if (found >= 0)
	{
		document.forms[0].restrictlistcache.value = "";
		if (n > 1)
		{
			for (i = 0; i < document.forms[0].accessaction.length; i++)
			{
				if (i != found)
					document.forms[0].restrictlistcache.value +=(document.forms[0].accessaction[i].value +","+
							document.forms[0].accesscondition[i].value +"," +
							document.forms[0].accessin[i].value + ":");
			}
		}
		RefreshPage();
	}
	else
	{
		alert("$text{'noselectaccess'}");
	}
}

function cacheaccesslist(n)
{
	document.forms[0].restrictlistcache.value = "";
	if (n > 1)
	{
		for (i = 0; i < document.forms[0].accessaction.length; i++)
		{
			document.forms[0].restrictlistcache.value +=(document.forms[0].accessaction[i].value +","+
							document.forms[0].accesscondition[i].value +"," +
							document.forms[0].accessin[i].value);
			if (i < (document.forms[0].accessaction.length - 1))
				document.forms[0].restrictlistcache.value += ":";
		}
	}
	else if (n == 1)
	{
		document.forms[0].restrictlistcache.value +=(document.forms[0].accessaction.value +","+
							document.forms[0].accesscondition.value +"," +
							document.forms[0].accessin.value);
	}
}

function checkselected(obj)
{
	if (!document.forms[0].allowanony.checked&&!document.forms[0].allowgroup.checked)
	{
		alert("$text{'must_select_one'}");
		obj.checked = true;
	}
}
function changeconnection()
{
	if (document.forms[0].maxconnect[0].checked)
	{
		document.forms[0].maxconnectionin.disabled = true;
		document.forms[0].maxconnectionin.value = "";
		document.forms[0].maxconnectionin.style.backgroundColor = "#d4d0c8";
	}
	else
	{
		document.forms[0].maxconnectionin.disabled = false;
		document.forms[0].maxconnectionin.style.backgroundColor = "#ffffff";
	}
}
</script>
EOF

#print "<hr>\n";
$spath =~ /(.*\/)[^\/]+$/;
&footer("index.cgi",  $text{'list_shares_return'}, "../folderman/index.cgi?dir=$1",  $text{'list_folders_return'});

if($alertmsg)
{
	print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
	print "alert(\"$alertmsg\")\n";
	print "</SCRIPT>\n";
}

ERROR_OUT:


